﻿using Sidvall.AuthorizationManager.UI.Messaging;

namespace Sidvall.AuthorizationManager.UI.ViewModels
{
	public sealed class MainWindowViewModel : Sidvall.AuthorizationManager.UI.ViewModels.Core.MainWindowViewModelBase
	{
		#region Public Members

		#region Title

		private string _Title;
		public string Title
		{
			get
			{
				return _Title;
			}
			set
			{
				if (_Title == value)
					return;
				_Title = value;
				RaisePropertyChanged("Title");
			}
		}

		#endregion
		#region ToolViewModel

		private ToolViewModel _ToolViewModel;
		public ToolViewModel ToolViewModel
		{
			get
			{
				return _ToolViewModel;
			}
			private set
			{
				_ToolViewModel = value;
				RaisePropertyChanged("ToolViewModel");
			}
		}

		#endregion

		#region Start

		public void Start(string title)
		{
			base.Start();

			_ApplicationTitle = title;
			this.IsBusyMessage = "LOADING";
			Subscribe<ServerManagerMessage>(OnServerManagerMessage);
			InitializeServer();

			var toolViewModel = new ToolViewModel();
			toolViewModel.Start();
			this.ToolViewModel = toolViewModel;
		}

		#endregion

		#endregion
		#region Private Members

		private string _ApplicationTitle;

		#region InitializeServer

		private void InitializeServer()
		{
			this.Title = _ApplicationTitle;
		}

		#endregion
		#region OnServerManagerMessage

		private void OnServerManagerMessage(ServerManagerMessage item)
		{
			InitializeServer();
		}

		#endregion

		#endregion
		#region Constructors

		public MainWindowViewModel()
		{
		}

		#endregion
	}
}
